package cn.edu.djtu.fw.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.edu.djtu.fw.dao.LostMapper;
import cn.edu.djtu.fw.model.Lost;
import cn.edu.djtu.fw.service.LostServiceI;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

@Service("lostService")
public class LostServiceImpl implements LostServiceI {
	private LostMapper lostMapper;

	public LostMapper getLostMapper() {
		return lostMapper;
	}

	@Autowired
	public void setLostMapper(LostMapper lostMapper) {
		this.lostMapper = lostMapper;
	}

	@Override
	public boolean delete(int lid) {
		try {
			lostMapper.deleteByPrimaryKey(lid);
			return true;
		} catch (Exception e) {
		}
		return false;
	}

	@Override
	public boolean update(Lost lost) {
		try {
			lostMapper.updateByPrimaryKey(lost);
			return true;
		} catch (Exception e) {
		}
		return false;
	}

	@Override
	public boolean insert(Lost lost) {
		try {
			lostMapper.insert(lost);
			return true;
		} catch (Exception e) {
		}
		return false;
	}

	@Override
	public Lost getLostById(int lid) {
		return lostMapper.selectByPrimaryKey(lid);
	}

	@Override
	public Map<String, Object> getAllLost(int page, int rows, Lost lost) {
		try {
			PageHelper.startPage(page, rows, true);
			List<Lost> losts = lostMapper.getAllLost(lost);
			Map<String, Object> lostMap = new HashMap<String, Object>();
			lostMap.put("rows", losts);
			lostMap.put("total", ((Page<Lost>) losts).getTotal());
			return lostMap;
		} catch (Exception e) {
		}
		return null;
	}
}
